package com.xca.is.utils;

import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class WebViewScriptUtils {

    public static void setWebView(WebView webView,String code) {
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        String htmlCode = "<html lang=\"zh-CN\">\n" +
                "    <style>\n" +
                "        body {\n" +
                "            font-family: Arial, sans-serif;\n" +
                "            line-height: 1.6;\n" +
                "            padding: 5px;\n" +
                "        }\n" +
                "    </style>\n" +
                "</head>\n" +
                "<body>\n" +
                code +
                "</body>\n" +
                "</html>";

        webView.loadDataWithBaseURL(null, htmlCode, "text/html", "UTF-8", null);
    }

    //设置页面背景
    public static void htmlContent(int[] codes, WebView webView) {
        /*  相同类型文件不宜使用多个效果，否则可能会覆盖  */
        StringBuilder sb = new StringBuilder();
        for (int item : codes) {
            Log.d("script", getScriptCode(item));
            sb.append(getScriptCode(item));
        }
        String script = sb.toString();

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        String htmlCode = "<html lang=\"zh-CN\">\n" +
                "    <style>\n" +
                "        body {\n" +
                "            font-family: Arial, sans-serif;\n" +
                "            line-height: 1.6;\n" +
                "            padding: 5px;\n" +
                "        }\n" +
                "    </style>\n" +
                "</head>\n" +
                "<body>\n" +
                script +
                "</body>\n" +
                "</html>";

        webView.loadDataWithBaseURL(null, htmlCode, "text/html", "UTF-8", null);

    }

    public static String getScriptCode(int code) {
        String scriptCode = "";
        switch (code) {
            case 1:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/xingkong\"></script>\n"; //星空
                break;
            case 2:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/csaixin\"></script>\n"; //彩色爱心
                break;
            case 3:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/bolang\"></script>\n";  //页面波浪
                break;
            case 4:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/long\"></script>\n"; // 龙 无效果
                break;
            case 5:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/kjbeijing\"></script>\n"; //科技背景
                break;
            case 6:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/sjcaidai\"></script>\n"; //随机彩带
                break;
            case 7:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/ciganxian\"></script>\n"; //磁感线
                break;
            case 8:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/hudongxingkong\"></script>\n"; //互动星空
                break;
            case 9:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/csqiqiu\"></script>\n"; //彩色气球
                break;
            case 10:
                scriptCode = "<script src=\"https://api.zxki.cn/api/yhpl\"></script>\n"; //樱花
                break;
            case 11:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/qccaihong\"></script>\n"; //七彩彩虹
                break;
            case 12:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/meihua\"></script>\n"; //梅花
                break;
            case 13:
                scriptCode = "<script src=\"https://api.zxki.cn/api/cjdl\"></script>\n"; //灯笼1
                break;
            case 14:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/denglong2\"></script>\n"; //新灯笼，无效
                break;
            case 15:
                //jquery,花海1，加载jQuery 要是网站有jQuery就不用了直接调用下面的花海即可
                scriptCode = "<script src=\"https://cdn.staticfile.net/jquery/3.7.1/jquery.min.js\"></script>\n" +
                        "<script src=\"https://api.cenguigui.cn/api/bg_flower\" type=\"text/javascript\" charset=\"utf-8\"></script>\n"; // 花海2  调用动态背景花海
                break;
            case 16:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/haipingmian\"></script>\n"; //海平面
                break;
            case 17:
                //点击音效
                scriptCode = "<script src=\"https://cdn.staticfile.net/jquery/3.5.1/jquery.min.js\"></script>\n" +
                        "<script src=\"https://api.cenguigui.cn/api/bjyinyue\"></script>";
                break;
            case 18:
                //雪花+颜色
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/xuehua\" rel=\"external nofollow\" ></script>\n" +
                        "<script>var sf = new Snowflakes({color: \"pink\"});</script>\n";
                break;

            //雷姆猫
            case 19:
                scriptCode = "<script src=\"https://api.cenguigui.cn/api/leimu\"></script>\n";
                break;
            //举牌小人，不好看
            case 20:
                scriptCode = "<img src=\"https://api.cenguigui.cn/api/jp/?msg=笒鬼鬼api\" alt=\"\" width=\"250px\">\n";
                break;

            //软萌小女孩，不好看 21-22
            case 21:
                scriptCode = "<img src=\"https://api.cenguigui.cn/api/shouxie/tu_jupai_girl.php?text=xca\" alt=\"\" width=\"2500px\">\n";
                break;
            case 22:
                scriptCode = "<img src=\"https://api.cenguigui.cn/api/shouxie/tu_jupai_mengmei.php?text=xca&id=2\" alt=\"\" width=\"250px\">\n";
                break;
            case 23 : //雪花2
                scriptCode = "<script src=\"https://api.zxki.cn/api/snow\"></script>\n";
                break;
        }
        return scriptCode;
    }
}
